//
//  AddSizeViewController.m
//  quickBatchManager
//
//  Created by 王定波 on 15/9/22.
//  Copyright © 2015年 jack. All rights reserved.
//

#import "EditSupplierViewController.h"

@interface EditSupplierViewController ()
{
    NSMutableArray *buttonList;
}
@end

@implementation EditSupplierViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
-(void)initUI
{
   
    self.view.backgroundColor=[UIColor clearColor];
    
    _noteTextView.layer.borderColor=[UIColor colorWithWhite:0.85 alpha:1].CGColor;
    _noteTextView.layer.borderWidth=0.5;
    _noteTextView.layer.cornerRadius=5;
    _noteTextView.clipsToBounds=YES;

    
    [_submitBtn bk_whenTapped:^{
        
        
        if([_nameField.text isBlank])
        {
            [self showAlert:@"名称必须填写"];
            return ;
        }
       
        if([_mobileField.text isBlank])
        {
            [self showAlert:@"电话必须填写"];
            return ;
        }
        
        if([_addressField.text isBlank])
        {
            [self showAlert:@"地址必须填写"];
            return ;
        }
        
        SupplierModel *model=[[SupplierModel alloc] init];
        model.contactName=_nameField.text;
        model.mobile=_mobileField.text;
        model.address=_addressField.text;
        model.note=_noteTextView.text;
        
        
        
        if(_supplier)
        {
            model.supplierId=_supplier.supplierId;
            [model updateToDB];
        }
        else [SupplierModel insertToDB:model];
        
        
        if([_delegate respondsToSelector:@selector(didChange:andData:)])
        {
            [_delegate didChange:ChangeTypeSupplier andData:nil];
        }
        
       self.splitViewController.viewControllers=@[[self.splitViewController.viewControllers objectAtIndex:0] ];
        
        
    }];
    
    
    if(_supplier)
    {
        _nameField.text=_supplier.contactName;
        _mobileField.text=_supplier.mobile;
        _addressField.text=_supplier.address;
        _noteTextView.text=_supplier.note;
    }
    
   
    

}


-(void) initData
{
    buttonList=[[NSMutableArray alloc] init];
}

@end
